package aszm.chahaospider.utils;

import java.io.IOException;
import java.net.SocketTimeoutException;

import org.apache.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

public class Utils {
	private static final Logger Log = Logger.getLogger(Utils.class.getName());

	/**
	 * 从网络获取HTML 文档
	 * 
	 * @param url
	 *            获取地址
	 * @return
	 */
	public static Document getDocumentDoc(String url) {
		Document doc = null;
		try {
			// 从URL直接加载 HTML 文档
			doc = Jsoup.connect(url).timeout(60 * 1000).get();
		} catch (SocketTimeoutException e) {
			Log.error("超时了重新开始抓取 url" + url);
			getDocumentDoc(url);
			Log.error(e);
		} catch (IOException e) {
			Log.error(e);
		}
		return doc;
	}
}
